package design_pattern.builder;

/**
 * see https://cloud.tencent.com/developer/article/1485977
 */

public class Student {
    private String name;
    private int age;
    private int gender;

    Student(String name, int age, int gender) {
        this.name = name;
        this.age = age;
        this.gender = gender;
    }

    public static StudentBuilder builder() {
        return new StudentBuilder();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getGender() {
        return gender;
    }

    public void setGender(int gender) {
        this.gender = gender;
    }

    // 省略get和set方法
    public String toString() {
        return "Student(name=" + this.getName() + ", age=" + this.getAge() + ", gender=" + this.getGender() + ")";
    }

    public static class StudentBuilder {
        private String name;
        private int age;
        private int gender;

        StudentBuilder() {
        }

        public StudentBuilder name(String name) {
            this.name = name;
            return this;
        }

        public StudentBuilder age(int age) {
            this.age = age;
            return this;
        }

        public StudentBuilder gender(int gender) {
            this.gender = gender;
            return this;
        }

        public Student build() {
            return new Student(this.name, this.age, this.gender);
        }

    }


    public static void main(String[] args) {
        Student student = Student.builder().name("小明")
                .age(10).gender(1).build();
        // Student(name=小明, age=10, gender=1)
        System.out.println(student);
    }
}